package com.kun.peng.system.mapper;

import com.kun.peng.mybatis.base.MyBaseMapper;
import com.kun.peng.system.domain.Dept;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Set;

/**
 * Created on 2021/11/17.
 *
 * @author xuebaopeng
 * Description
 */
@Mapper
public interface DeptMapper extends MyBaseMapper<Dept> {

    /**
     * 获取顶级部门
     * @return /
     */
    List<Dept> findByPidIsNull();

    /**
     * 根据 PID 查询
     * @param pid pid
     * @return
     */
    List<Dept> findByPid(@Param("pid")Long pid);
    /**
     * 根据角色ID 查询
     * @param roleId 角色ID
     * @return
     */
    Set<Dept> findByRoleId(@Param("roleId") Long roleId);

    /**
     * 判断是否存在子节点
     * @param pid
     * @return
     */
    int countByPid(Long pid);


    /**
     * 根据ID更新sub_count
     * @param count
     * @param id
     */
    @Update(value = " update sys_dept set sub_count = #{count} where dept_id = #{id} ")
    void updateSubCntById(@Param("count")Integer count, @Param("id")Long id);

}
